const mongoose = require("./db")


const userSchema = new mongoose.Schema({
    username: String,
    password: String
})

const peopleSchema = new mongoose.Schema({
    name : String,
    introduce : String,
    comment : String, 
    video : String,
    cateid :{
        type : mongoose.Schema.Types.ObjectId,
        ref : "cate"
    }
})

const cateSchema = new mongoose.Schema({
    name : String
})




const newsSchema = new mongoose.Schema({
    img: String,//用户头像
    name: String,//用户名
    userId:Number,//用户id
    address:String,//地址
    desc:String,//简介
    praised:Number,//点赞
    fans:Number,//粉丝
    follow:Number,//关注
    concern:{
        type:Boolean,
        default:false
   },//控制是否关注
})
const newsModel = mongoose.model("news", newsSchema,"news")

//文章/视频的类别
const categorySchema = new mongoose.Schema({
    name:String,//类别名称
})
const categoryModel = mongoose.model("category", categorySchema,"category")

//文章表
const articleSchema = new mongoose.Schema({
   desc:String,//文章内容
   img:String,//文章图片
   title:String,//文章标题
   categoryId:{
        type:mongoose.Schema.Types.ObjectId,
        ref:"category"
   },//文章类别
   userId:{
        type:mongoose.Schema.Types.ObjectId,
        ref:"news"
   },//发布该文章的用户
   time:{
        type:Date,
        default:Date.now()
   },//发布时间
   praise:Number,//点赞
   comment:Number,//评论
   collect:{
        type:Boolean,
        default:false
   },//收藏
   
})
const articleModel = mongoose.model("article", articleSchema,"article")

//视频表
const videoSchema = new mongoose.Schema({
    video:String,//视频地址
    title:String,//视频标题
    categoryId:{
        type:mongoose.Schema.Types.ObjectId,
        ref:"category"
    },//视频类别
    userId:{
        type:mongoose.Schema.Types.ObjectId,
        ref:"news"
    },//发布该视频的用户
     time:{
        type:Date,
        default:Date.now()
    },//发布时间
    sum:Number,//播放次数
    praise:Number,//点赞
    comment:Number,//评论
    collect:{
        type:Boolean,
        default:false
    },//收藏
})
const videoModel = mongoose.model("video", videoSchema,"video")
const userModel = mongoose.model("user", userSchema,"user")
const people = mongoose.model("people",peopleSchema,"people")
const cate = mongoose.model("cate",cateSchema,"cate")


module.exports = {
    userModel,
    newsModel,
    categoryModel,
    articleModel,
    videoModel,
    people,
    cate
}